/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DataConverters.DataReaders.readersImpl;

import DataConverters.DataReaders.AbstractDataReader;
import DataConverters.interfaces.IConvertable;
import DataConverters.exceptions.DataReaderException;
import common.gui.progress.IProgressItem;
import DataConverters.interfaces.dataformulaobject.intefaces.Cell;
import FileInformation.FileInformation;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInput;
import java.io.ObjectInputStream;
import java.util.SortedSet;

/**
 *
 * @author Nobody
 */
public class GDAReader extends AbstractDataReader {

    public GDAReader(IProgressItem progressLabel, IConvertable source) {
        super(progressLabel, source);
    }

    @Override
    public void read() throws DataReaderException {
        try {
            FileInformation fileInformation = (FileInformation) source;
            InputStream fileStream = new FileInputStream(fileInformation.getFile().getAbsolutePath());
            InputStream buffer = new BufferedInputStream(fileStream);
            ObjectInput input = new ObjectInputStream(buffer);
            try {
                Object readedObject = input.readObject();
                if (readedObject instanceof SortedSet) {
                    formulasList = (SortedSet<Cell>) readedObject;
                }
            } finally {
                input.close();
            }
        } catch (ClassNotFoundException ex) {
            throw new DataReaderException(ex);
        } catch (IOException ex) {
            throw new DataReaderException(ex);
        }
    }
}
